<template>
    <div class="app-container">
        <el-card shadow="never">
            <!-- 条件查询 -->
            <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="120px"
                     @keyup.enter.native="submitSearch" @submit.native.prevent>
                <el-row>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="租户:" prop="tenant.name.value">
                            <el-input v-model="queryParams.tenant.name.value" placeholder="请输入租户" clearable/>
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="房间名称:" prop="liveRoom.roomName.value">
                            <el-input v-model="queryParams.liveRoom.roomName.value" placeholder="请输入房间名称" clearable/>
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="用户昵称:" prop="myUser.nickname.value">
                            <el-input v-model="queryParams.myUser.nickname.value" placeholder="请输入用户昵称" clearable/>
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="姓名:" prop="name.value">
                            <el-input v-model="queryParams.name.value" placeholder="请输入姓名" clearable/>
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="联系方式:" prop="tel.value">
                            <el-input v-model="queryParams.tel.value" placeholder="请输入联系方式" clearable/>
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item class="ele-text-right" label-width="50px">
                            <el-button type="primary" size="mini" @click="submitSearch" icon="el-icon-search"
                                       class="ele-btn-icon">搜索
                            </el-button>
                            <el-button @click="resetQuery" size="mini" icon="el-icon-refresh">重置</el-button>

                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>


            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5" v-if="false">
                    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="open" v-hasPermi="api.add">
                        添加
                    </el-button>
                </el-col>
                <el-col :span="1.5" v-if="false">
                    <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                               @click="handleDelete" v-hasPermi="api.delete">删除
                    </el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="warning" plain icon="el-icon-download" size="mini" v-loading="exportLoading"
                               @click="handleExport" v-hasPermi="api.export">导出
                    </el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="initIndex" :columns="columns"
                               printId="#quickadmin"></right-toolbar>
            </el-row>

            <!-- 列表 -->
            <qa-table
                :source="tableData"
                :columns="columns"
                :selection="false"
                :loading="loading"
                @sortChange="sortChange"
                @statusChange="statusChange"
                @selectionChange="selectionChange"
                id="quickadmin"
            >
                <template v-slot:action>
                    <el-table-column label="操作" width="180" v-if="false">
                        <template slot-scope="scope">
                            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)"
                                       v-hasPermi="api.edit">编辑
                            </el-button>
                            <el-button size="mini" type="text" icon="el-icon-tickets" @click="handleDetail(scope.row)"
                                       v-hasPermi="api.find">详情
                            </el-button>
                            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                                       v-hasPermi="api.delete">删除
                            </el-button>
                        </template>
                    </el-table-column>
                </template>
            </qa-table>

            <!-- 分页 -->
            <pagination :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="initIndex"/>
        </el-card>

        <!-- 编辑弹窗 -->
        <el-dialog :title="!disabled ? '编辑' : '详情'" :visible="editOpen" :before-close="beforeClose" destroy-on-close>
            <EditForm ref="editForm" :findFormData="findFormData" :disabled="disabled" @submitForm="submitForm"
                      :editFormParams="editFormParams" @editFormCancel="beforeClose"/>
        </el-dialog>
    </div>
</template>

<script>
import {curdMixin} from '@/mixins/curdMixin'
import EditForm from './EditFormCom'

export default {
    name: 'Curd',
    mixins: [curdMixin],
    components: {EditForm},
    props: {
        queryObj: {
            type: Object,
            default: () => {
                return {}
            }
        }
    },
    data() {
        return {
            // table结构
            columns: [
                {
                    visible: true,
                    label: '编号',
                    prop: 'id',
                },
                {
                    visible: true,
                    label: '租户',
                    prop: 'tenant.name',
                },
                {
                    visible: true,
                    label: '房间名称',
                    prop: 'liveRoom.roomName',
                },
                {
                    visible: true,
                    label: '用户昵称',
                    prop: 'myUser.nickname',
                },
                {
                    visible: true,
                    label: '姓名',
                    prop: 'name',
                },
                {
                    visible: true,
                    label: '联系方式',
                    prop: 'tel',
                },
                {
                    visible: true,
                    label: '创建时间',
                    prop: 'create_time',
                },
                {
                    visible: true,
                    label: '更新时间',
                    prop: 'update_time',
                },
            ],
            // 接口地址
            api: {
                index: `/admin/px.liveroom_enlist/index`,
                find: `/admin/px.liveroom_enlist/find`,
                add: `/admin/px.liveroom_enlist/add`,
                edit: `/admin/px.liveroom_enlist/edit`,
                delete: `/admin/px.liveroom_enlist/delete`,
                export: `/admin/px.liveroom_enlist/export`,
                status: `/admin/px.liveroom_enlist/status`
            },
            editFormParams: {},
            // 搜索表单是否展开
            searchExpand: false,
            // 查询参数
            queryParams: {
                name: {value: undefined, op: '%like%'},
                tel: {value: undefined, op: '%like%'},
                tenant: {
                    id: {value: undefined, op: '='},
                    name: {value: undefined, op: '%like%'},
                },
                liveRoom: {
                    id: {value: undefined, op: '='},
                    roomName: {value: undefined, op: '%like%'},
                },
                myUser: {
                    uid: {value: undefined, op: '='},
                    nickname: {value: undefined, op: '%like%'},
                },
            },
            tableIsJoinLoad: false
        }
    },
    created() {
        if (this.queryObj.tenant_id) {
            this.queryParams.tenant.id.value = this.queryObj.tenant_id
        }
        if (this.queryObj.room_id) {
            this.queryParams.liveRoom.id.value = this.queryObj.room_id
        }
        this.initIndex()
    }
}
</script>
